package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.ReadPartieModel;
import com.ruitu.health_2.ui.common.ReadPartieListActivity;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.home.ReadPartie;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

// 读书会模块
public class ReadPartiePresenter {

    // 读书会列表
    public static class ReadPartieListP extends BasePresenter<ReadPartieListActivity, ReadPartieModel.ReadPartieListM> {
        public Disposable reqReadPartieList(int size, int num) {
            return m.reqReadPartieList(size, num).subscribe(new Consumer<BaseResult2<PageModel2<ReadPartie>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<ReadPartie>> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()) {
                        v.onReqComplete(1, true, result.getData());
                    } else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }

        // 读书会column列表
        public Disposable reqReadPartieColumnList(String posId, int size, int num) {
            return m.reqReadPartieColumnList(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<ReadPartie>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<ReadPartie>> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()) {
                        v.onReqComplete(1, true, result.getData());
                    } else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }
}
